#include "QSketchCircleAction.h"
#include "Core/MainWindow.h"
#include "Sketch/QSketchManager.h"
#include "Core/TempActorManager.h"

QSketchCircleAction::QSketchCircleAction(QSketchManager* parent, MainWindow* mainWindow)
	: QSketchCurveAction(parent, mainWindow)
{

}

QSketchCircleAction::~QSketchCircleAction()
{
}

void QSketchCircleAction::StartCreate()
{
	std::cout << "QSketchCircleAction::StartCreate" << std::endl;
}

void QSketchCircleAction::OnMouseMove(const gp_Pnt& point)
{
}

void QSketchCircleAction::OnLeftDown(const gp_Pnt& point)
{
	if (!bIsConfirmCenter)
	{
		bIsConfirmCenter = true;
		m_center = point;

		m_centerPointActorID = m_mainWindow->GetTempActorManager()->GetUnallocatedActor(0.01);
		m_mainWindow->GetTempActorManager()->SetActorVisible(m_centerPointActorID, true, point);
	}
	else
	{
		m_radius = point.Distance(m_center);
		Handle(QIVtkSelectionPipeline) actor = m_mainWindow->createCircle(m_center, m_radius, m_sketchManager->GetCurrentNormal());
		actor->m_featureShape.reset(new FeatureShapeCircle(actor->OccShape(), m_center, m_radius, m_sketchManager->GetCurrentNormal()));
		m_sketchManager->m_points[EVertexType::CircleCenterVertex].push_back(m_center);
		m_sketchManager->EndCreateSketchCurve(actor);
	}
}

void QSketchCircleAction::Reset()
{
	m_mainWindow->GetTempActorManager()->FreeActor(m_centerPointActorID);

	m_center = gp_Pnt();
    m_radius = 0;
    bIsConfirmCenter = false;
    m_centerPointActorID = 255;
}
